﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace KTV项目
{
    public partial class chazhao : Form
    {
        public chazhao()
        {
            InitializeComponent();
        }
        Bestdao dao = new Bestdao();
        private void button1_Click(object sender, EventArgs e)
        {
            //创建SQL语句来将需要查的数据带入SQL语句中
            string sql =string.Format(@"select song_id,song_name,song_ab,songtype_name,song_url,song_piay_count from song_info inner join song_type on song_info.songtype_id=song_type.songtype_id
where song_name like '%{0}%' and songtype_name='{1}'", textBox1.Text,comboBox1.Text);
            dataGridView1.DataSource = dao.table(sql);
        }

        private void chazhao_Load(object sender, EventArgs e)
        {
            //将查询到的数据绑定到下拉框中显示
            string sql = "select songtype_name from song_type";
            comboBox1.DisplayMember = "songtype_name";
            comboBox1.ValueMember = "songtype_id";
            comboBox1.DataSource = dao.table(sql);
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void 删除歌曲ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //获得用户选中的这一行数据
            if (dataGridView1.SelectedRows.Count==1)
            {
                //获得用户选中的这条数据，获得歌曲ID之后，带入SQL语句进行查询
                DataGridViewRow row = this.dataGridView1.SelectedRows[0];
                string sql = string.Format("delete song_info where song_id={0}",dataGridView1.SelectedRows[0].Cells[0].Value.ToString());
                int he = dao.query(sql);
                if (he!=0)
                {
                    MessageBox.Show("删除成功","提示");
                }
                else
                {
                    MessageBox.Show("删除失败","提示");
                }
            }
        }

        private void 修改歌曲ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //将数据传递给新打开的窗体来显示
            gaidong gai = new gaidong();
            if (dataGridView1.SelectedRows.Count==1)
            {
                DataGridViewRow row = this.dataGridView1.SelectedRows[0];
                gai.texid.Text = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
                gai.texname.Text = dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
                gai.texpin.Text = dataGridView1.SelectedRows[0].Cells[2].Value.ToString();
                gai.comtype.Text = dataGridView1.SelectedRows[0].Cells[3].Value.ToString();
                gai.texturl.Text = dataGridView1.SelectedRows[0].Cells[4].Value.ToString();
            }
            gai.Show();
        }
    }
}
